{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction to atomman: CIF conversions\n",
    "\n",
    "__Lucas M. Hale__, [lucas.hale@nist.gov](mailto:lucas.hale@nist.gov?Subject=ipr-demo), _Materials Science and Engineering Division, NIST_.\n",
    "    \n",
    "[Disclaimers](http://www.nist.gov/public_affairs/disclaimer.cfm) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1. Introduction<a id='section1'></a>\n",
    "\n",
    "The Crystallographic Information File (CIF) format is a standard for representing crystallographic information and is used by different crystal databases.  Loading CIF files in atomman requires that the [diffpy.structure](https://github.com/diffpy/diffpy.structure) package be installed.\n",
    "\n",
    "Atomman supports loading atomic structures from CIF files but not writing CIF files based on the structures.   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Library Imports**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "atomman version = 1.4.0\n",
      "Notebook executed on 2021-08-04\n"
     ]
    }
   ],
   "source": [
    "# Standard Python libraries\n",
    "import datetime\n",
    "\n",
    "# http://www.numpy.org/\n",
    "import numpy as np\n",
    "\n",
    "import atomman as am\n",
    "import atomman.unitconvert as uc\n",
    "\n",
    "# Show atomman version\n",
    "print('atomman version =', am.__version__)\n",
    "\n",
    "# Show date of Notebook execution\n",
    "print('Notebook executed on', datetime.date.today())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "CIF file taken from Crystallography Open Database (COD): http://www.crystallography.net/"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "cif = \"\"\"#------------------------------------------------------------------------------\n",
    "#$Date: 2016-02-13 21:28:24 +0200 (Sat, 13 Feb 2016) $\n",
    "#$Revision: 176429 $\n",
    "#$URL: svn://www.crystallography.net/cod/cif/1/54/12/1541266.cif $\n",
    "#------------------------------------------------------------------------------\n",
    "#\n",
    "# This file is available in the Crystallography Open Database (COD),\n",
    "# http://www.crystallography.net/\n",
    "#\n",
    "# All data on this site have been placed in the public domain by the\n",
    "# contributors.\n",
    "#\n",
    "data_1541266\n",
    "loop_\n",
    "_publ_author_name\n",
    "'Mueller, M. H.'\n",
    "_publ_section_title\n",
    ";\n",
    " The lattice parameter of tantalum\n",
    ";\n",
    "_journal_issue                   8\n",
    "_journal_name_full               'Scripta Metallurgica'\n",
    "_journal_page_first              693\n",
    "_journal_page_last               693\n",
    "_journal_paper_doi               10.1016/0036-9748(77)90141-7\n",
    "_journal_volume                  11\n",
    "_journal_year                    1977\n",
    "_chemical_formula_sum            Ta\n",
    "_chemical_name_systematic        Ta\n",
    "_space_group_IT_number           229\n",
    "_symmetry_space_group_name_Hall  '-I 4 2 3'\n",
    "_symmetry_space_group_name_H-M   'I m -3 m'\n",
    "_cell_angle_alpha                90\n",
    "_cell_angle_beta                 90\n",
    "_cell_angle_gamma                90\n",
    "_cell_formula_units_Z            2\n",
    "_cell_length_a                   3.30256\n",
    "_cell_length_b                   3.30256\n",
    "_cell_length_c                   3.30256\n",
    "_cell_volume                     36.021\n",
    "_citation_journal_id_ASTM        SCRMBU\n",
    "_cod_data_source_file            Mueller_SCRMBU_1977_100.cif\n",
    "_cod_data_source_block           Ta1\n",
    "_cod_original_cell_volume        36.0207\n",
    "_cod_original_formula_sum        Ta1\n",
    "_cod_database_code               1541266\n",
    "loop_\n",
    "_symmetry_equiv_pos_as_xyz\n",
    "x,y,z\n",
    "-y,x,z\n",
    "-x,-y,z\n",
    "y,-x,z\n",
    "x,-y,-z\n",
    "y,x,-z\n",
    "-x,y,-z\n",
    "-y,-x,-z\n",
    "z,x,y\n",
    "-x,z,y\n",
    "-z,-x,y\n",
    "x,-z,y\n",
    "z,-x,-y\n",
    "x,z,-y\n",
    "-z,x,-y\n",
    "-x,-z,-y\n",
    "y,z,x\n",
    "y,-z,-x\n",
    "z,y,-x\n",
    "-y,z,-x\n",
    "-z,-y,-x\n",
    "-y,-z,x\n",
    "z,-y,x\n",
    "-z,y,x\n",
    "-x,-y,-z\n",
    "y,-x,-z\n",
    "x,y,-z\n",
    "-y,x,-z\n",
    "-x,y,z\n",
    "-y,-x,z\n",
    "x,-y,z\n",
    "y,x,z\n",
    "-z,-x,-y\n",
    "x,-z,-y\n",
    "z,x,-y\n",
    "-x,z,-y\n",
    "-z,x,y\n",
    "-x,-z,y\n",
    "z,-x,y\n",
    "x,z,y\n",
    "-y,-z,-x\n",
    "-y,z,x\n",
    "-z,-y,x\n",
    "y,-z,x\n",
    "z,y,x\n",
    "y,z,-x\n",
    "-z,y,-x\n",
    "z,-y,-x\n",
    "x+1/2,y+1/2,z+1/2\n",
    "-y+1/2,x+1/2,z+1/2\n",
    "-x+1/2,-y+1/2,z+1/2\n",
    "y+1/2,-x+1/2,z+1/2\n",
    "x+1/2,-y+1/2,-z+1/2\n",
    "y+1/2,x+1/2,-z+1/2\n",
    "-x+1/2,y+1/2,-z+1/2\n",
    "-y+1/2,-x+1/2,-z+1/2\n",
    "z+1/2,x+1/2,y+1/2\n",
    "-x+1/2,z+1/2,y+1/2\n",
    "-z+1/2,-x+1/2,y+1/2\n",
    "x+1/2,-z+1/2,y+1/2\n",
    "z+1/2,-x+1/2,-y+1/2\n",
    "x+1/2,z+1/2,-y+1/2\n",
    "-z+1/2,x+1/2,-y+1/2\n",
    "-x+1/2,-z+1/2,-y+1/2\n",
    "y+1/2,z+1/2,x+1/2\n",
    "y+1/2,-z+1/2,-x+1/2\n",
    "z+1/2,y+1/2,-x+1/2\n",
    "-y+1/2,z+1/2,-x+1/2\n",
    "-z+1/2,-y+1/2,-x+1/2\n",
    "-y+1/2,-z+1/2,x+1/2\n",
    "z+1/2,-y+1/2,x+1/2\n",
    "-z+1/2,y+1/2,x+1/2\n",
    "-x+1/2,-y+1/2,-z+1/2\n",
    "y+1/2,-x+1/2,-z+1/2\n",
    "x+1/2,y+1/2,-z+1/2\n",
    "-y+1/2,x+1/2,-z+1/2\n",
    "-x+1/2,y+1/2,z+1/2\n",
    "-y+1/2,-x+1/2,z+1/2\n",
    "x+1/2,-y+1/2,z+1/2\n",
    "y+1/2,x+1/2,z+1/2\n",
    "-z+1/2,-x+1/2,-y+1/2\n",
    "x+1/2,-z+1/2,-y+1/2\n",
    "z+1/2,x+1/2,-y+1/2\n",
    "-x+1/2,z+1/2,-y+1/2\n",
    "-z+1/2,x+1/2,y+1/2\n",
    "-x+1/2,-z+1/2,y+1/2\n",
    "z+1/2,-x+1/2,y+1/2\n",
    "x+1/2,z+1/2,y+1/2\n",
    "-y+1/2,-z+1/2,-x+1/2\n",
    "-y+1/2,z+1/2,x+1/2\n",
    "-z+1/2,-y+1/2,x+1/2\n",
    "y+1/2,-z+1/2,x+1/2\n",
    "z+1/2,y+1/2,x+1/2\n",
    "y+1/2,z+1/2,-x+1/2\n",
    "-z+1/2,y+1/2,-x+1/2\n",
    "z+1/2,-y+1/2,-x+1/2\n",
    "loop_\n",
    "_atom_site_label\n",
    "_atom_site_type_symbol\n",
    "_atom_site_fract_x\n",
    "_atom_site_fract_y\n",
    "_atom_site_fract_z\n",
    "_atom_site_occupancy\n",
    "_atom_site_U_iso_or_equiv\n",
    "Ta1 Ta 0 0 0 1 0.0\n",
    "\"\"\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2. atomman.load('cif')<a id='section2'></a>\n",
    "\n",
    "Parameters\n",
    "\n",
    "- **cif** (*str or file-like object*) The cif content to read.\n",
    "        \n",
    "Returns\n",
    "\n",
    "- **system** (*atomman.System*) An atomman representation of a system."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "avect =  [ 3.303,  0.000,  0.000]\n",
      "bvect =  [ 0.000,  3.303,  0.000]\n",
      "cvect =  [ 0.000,  0.000,  3.303]\n",
      "origin = [ 0.000,  0.000,  0.000]\n",
      "natoms = 2\n",
      "natypes = 1\n",
      "symbols = ('Ta',)\n",
      "pbc = [ True  True  True]\n",
      "per-atom properties = ['atype', 'pos']\n",
      "     id |   atype |  pos[0] |  pos[1] |  pos[2]\n",
      "      0 |       1 |   0.000 |   0.000 |   0.000\n",
      "      1 |       1 |   1.651 |   1.651 |   1.651\n",
      "   atype   pos[0]   pos[1]   pos[2]\n",
      "0      1  0.00000  0.00000  0.00000\n",
      "1      1  1.65128  1.65128  1.65128\n"
     ]
    }
   ],
   "source": [
    "try:\n",
    "    cif_system = am.load('cif', cif)\n",
    "except AssertionError as e:\n",
    "    print('AssertionError:', e)\n",
    "else:\n",
    "    print(cif_system)\n",
    "    print(cif_system.atoms_df())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    " "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
